package org.wutopia.labcloud.domain.uaa.controller;

import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.wutopia.labcloud.domain.uaa.controller.vo.input.UserCreateAuthorityInputVO;
import org.wutopia.labcloud.domain.uaa.controller.vo.output.UserAuthorityListOutputVO;
import org.wutopia.labcloud.domain.uaa.service.UserAuthorityService;
import org.wutopia.labcloud.library.common.base.CodedMessage;
import org.wutopia.labcloud.library.common.base.CommonResponse;
import org.wutopia.labcloud.library.common.base.PageInputVO;
import org.wutopia.labcloud.library.common.base.PageOutputVO;

@RestController
@RequestMapping("/user/auth/authority")
@AllArgsConstructor
public class UserAuthorityController {

    private UserAuthorityService userAuthorityService;

    @PostMapping("/create")
    public ResponseEntity<CodedMessage<String>> createRole(@RequestBody UserCreateAuthorityInputVO vo) {

        if(vo == null || vo.getAuthorityName() == null) {
            return CommonResponse.failure("入参错误");
        }
        userAuthorityService.createAuthority(vo);
        return CommonResponse.success();
    }

    @PostMapping("/list")
    public ResponseEntity<CodedMessage<PageOutputVO<UserAuthorityListOutputVO>>> list(@RequestBody PageInputVO vo) {

        if(vo == null || vo.getSize() == null || vo.getPage() == null) {
            return CommonResponse.failure("入参错误");
        }

        PageOutputVO<UserAuthorityListOutputVO> list = userAuthorityService.list(vo);


        return CommonResponse.successWithData(list);
    }

}
